extends PropertyFindSetter


class_name AttributeBinder
"""
属性字段变更时修改对象的值
"""


@export var attribute: String = ""
@export var character: CharacterComponent = null


func __check_exports() -> Dictionary:
    return IComponent.merge({
        "attribute": func(): return attribute != "",
        "character": IComponent.find_up_nearby.bind(self, func(x): return x is CharacterComponent, character),
    }, super.__check_exports())

func __init_hooks() -> Dictionary:
    return IComponent.merge({
        character.meta.event_property_changed: on_property_changed,
    }, super.__init_hooks())

func on_property_changed(attrs: CustomAttributes, attr: Attribute, attr_property: String, new_value: int) -> void:
    if attr_property == attribute and __get_wrapper_and_property() and cached_w:
        __set_value(cached_w, cached_p, new_value)

func execute() -> void:
    pass
